package dao

import (
	"zk1/srv/global"
	"zk1/srv/model"
)

func Login(name string) (user model.User, err error) {
	err = global.DB.Where("user_name = ?", name).Find(&user).Limit(1).Error
	if err != nil {
		return model.User{}, err
	}
	return user, nil
}

func VideoList[T any](data *[]T) bool {
	err := global.DB.Find(data).Limit(10).Error
	if err != nil {
		return false
	}
	return true
}

func VideoListOne[T any](where *T, data *model.Video) bool {
	err := global.DB.Where(where).Find(data).Limit(1).Error
	if err != nil {
		return false
	}
	return true
}

func Login1(id int64) (user model.User, err error) {
	err = global.DB.Where("id = ?", id).Find(&user).Limit(1).Error
	if err != nil {
		return model.User{}, err
	}
	return user, nil
}
